package com.quectel.util.aspect.lock;

import com.quectel.util.aspect.lock.annotation.Lock;
import lombok.extern.slf4j.Slf4j;
import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
import org.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;

/**
 * 定义切点和方法拦截器的绑定
 *
 * @author caolu
 * @email louis.cao@quectel.com
 * @date 2023-11-28 14:17:00
 */
@Slf4j
public class DistributedLockPointCutAdvisor extends AbstractPointcutAdvisor {
    private static final Pointcut POINTCUT = new AnnotationMatchingPointcut(null, Lock.class);

    private DistributedLockMethodInterceptor distributedLockMethodInterceptor;

    public DistributedLockPointCutAdvisor(DistributedLockMethodInterceptor distributedLockMethodInterceptor) {
        this.distributedLockMethodInterceptor = distributedLockMethodInterceptor;
    }

    @Override
    public Pointcut getPointcut() {
        return POINTCUT;
    }

    @Override
    public Advice getAdvice() {
        return this.distributedLockMethodInterceptor;
    }
}
